package tt.dz.order.pojo;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import tt.dz.order.dao.BaseDAOUtil;

/**
 * @Title 微信支付回调记录
 * @author zhoutian   
 * @date 2015-11-26
 */
public class WeiXinPayCallBackRecord {
	//商户系统唯一订单号
	private String orderNo;
	//返回状态码,SUCCESS/FAIL 此字段是通信标识，非交易标识，交易是否成功需要查看result_code来判断
	private String returnCode;
	//返回信息
	private String returnMsg;
	//公众账号ID,微信分配的公众账号ID（企业号corpid即为此appId）
	private String appId;
	//商户号,微信支付分配的商户号
	private String partnerNo;
	//设备号,微信支付分配的终端设备号
	private String deviceInfo;
	//随机字符串，不长于32位
	private String nonceStr;
	//签名,用于验证回调请求参数是否被篡改过
	private String sign;
	//业务结果,SUCCESS/FAIL
	private String resultCode;
	//错误代码,错误返回的信息描述
	private String errCode;
	//错误代码描述,错误返回的信息描述
	private String errCodeDes;
	//用户标识,用户在商户appid下的唯一标识
	private String openId;
	//是否关注公众账号,用户是否关注公众账号，Y-关注，N-未关注，仅在公众账号类型支付有效
	private String isSubscribe;
	//交易类型,JSAPI、NATIVE、APP
	private String tradeType;
	//付款银行,银行类型，采用字符串类型的银行标识
	private String bankType;
	//订单总金额，单位为分
	private String totalFee;
	//货币种类,货币类型，符合ISO4217标准的三位字母代码，默认人民币：CNY
	private String feeType;
	//现金支付金额,订单现金支付金额
	private String cashFee;
	//现金支付货币类型,符合ISO4217标准的三位字母代码，默认人民币：CNY
	private String cashFeeType;
	//代金券或立减优惠金额, 代金券或立减优惠金额<=订单总金额，订单总金额-代金券或立减优惠金额=现金支付金额
	private String couponFee;
	//代金券或立减优惠使用数量
	private String couponCount;
	//微信支付订单号
	private String tradeNo;
	//商家数据包，原样返回
	private String attach;
	//支付完成时间，格式为yyyyMMddHHmmss
	private String timeEnd;
	//创建时间
	private Date createTime;
	//支付渠道appid
	private String bizSystemCode;

	public String getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}

	public String getReturnCode() {
		return returnCode;
	}

	public void setReturnCode(String returnCode) {
		this.returnCode = returnCode;
	}

	public String getReturnMsg() {
		return returnMsg;
	}

	public void setReturnMsg(String returnMsg) {
		this.returnMsg = returnMsg;
	}

	public String getAppId() {
		return appId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}

	public String getPartnerNo() {
		return partnerNo;
	}

	public void setPartnerNo(String partnerNo) {
		this.partnerNo = partnerNo;
	}

	public String getDeviceInfo() {
		return deviceInfo;
	}

	public void setDeviceInfo(String deviceInfo) {
		this.deviceInfo = deviceInfo;
	}

	public String getNonceStr() {
		return nonceStr;
	}

	public void setNonceStr(String nonceStr) {
		this.nonceStr = nonceStr;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getResultCode() {
		return resultCode;
	}

	public void setResultCode(String resultCode) {
		this.resultCode = resultCode;
	}

	public String getErrCode() {
		return errCode;
	}

	public void setErrCode(String errCode) {
		this.errCode = errCode;
	}

	public String getErrCodeDes() {
		return errCodeDes;
	}

	public void setErrCodeDes(String errCodeDes) {
		this.errCodeDes = errCodeDes;
	}

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}

	public String getIsSubscribe() {
		return isSubscribe;
	}

	public void setIsSubscribe(String isSubscribe) {
		this.isSubscribe = isSubscribe;
	}

	public String getTradeType() {
		return tradeType;
	}

	public void setTradeType(String tradeType) {
		this.tradeType = tradeType;
	}

	public String getBankType() {
		return bankType;
	}

	public void setBankType(String bankType) {
		this.bankType = bankType;
	}

	public String getTotalFee() {
		return totalFee;
	}

	public void setTotalFee(String totalFee) {
		this.totalFee = totalFee;
	}

	public String getFeeType() {
		return feeType;
	}

	public void setFeeType(String feeType) {
		this.feeType = feeType;
	}

	public String getCashFee() {
		return cashFee;
	}

	public void setCashFee(String cashFee) {
		this.cashFee = cashFee;
	}

	public String getCashFeeType() {
		return cashFeeType;
	}

	public void setCashFeeType(String cashFeeType) {
		this.cashFeeType = cashFeeType;
	}

	public String getCouponFee() {
		return couponFee;
	}

	public void setCouponFee(String couponFee) {
		this.couponFee = couponFee;
	}

	public String getCouponCount() {
		return couponCount;
	}

	public void setCouponCount(String couponCount) {
		this.couponCount = couponCount;
	}

	public String getTradeNo() {
		return tradeNo;
	}

	public void setTradeNo(String tradeNo) {
		this.tradeNo = tradeNo;
	}

	public String getAttach() {
		return attach;
	}

	public void setAttach(String attach) {
		this.attach = attach;
	}

	public String getTimeEnd() {
		return timeEnd;
	}

	public void setTimeEnd(String timeEnd) {
		this.timeEnd = timeEnd;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public String getBizSystemCode() {
		return bizSystemCode;
	}

	public void setBizSystemCode(String bizSystemCode) {
		this.bizSystemCode = bizSystemCode;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public WeiXinPayCallBackRecord(){
		
	}
	
	public WeiXinPayCallBackRecord(Map<String, Object> callBackMap){
		this.orderNo = (String) callBackMap.get("out_trade_no");
		this.returnCode = (String) callBackMap.get("return_code");
		this.returnMsg = (String) callBackMap.get("return_msg");
		this.appId = (String) callBackMap.get("appid");
		this.partnerNo = (String) callBackMap.get("mch_id");
		this.deviceInfo = (String) callBackMap.get("device_info");
		this.nonceStr = (String) callBackMap.get("nonce_str");
		this.sign = (String) callBackMap.get("sign");
		this.resultCode = (String) callBackMap.get("result_code");
		this.errCode = (String) callBackMap.get("err_code");
		this.errCodeDes = (String) callBackMap.get("err_code_des");
		this.openId = (String) callBackMap.get("openid");
		this.isSubscribe = (String) callBackMap.get("is_subscribe");
		this.tradeType = (String) callBackMap.get("trade_type");
		this.bankType = (String) callBackMap.get("bank_type");
		this.totalFee = (String) callBackMap.get("total_fee");
		this.feeType = (String) callBackMap.get("fee_type");
		this.cashFee = (String) callBackMap.get("cash_fee");
		this.cashFeeType = (String) callBackMap.get("cash_fee_type");
		this.couponFee = (String) callBackMap.get("coupon_fee");
		this.couponCount = (String) callBackMap.get("coupon_count");
		this.tradeNo = (String) callBackMap.get("transaction_id");
		this.attach = (String) callBackMap.get("attach");
		this.timeEnd = (String) callBackMap.get("time_end");
		this.bizSystemCode = (String) callBackMap.get("attach");
		this.createTime = new Date();
	}
	
	public void save(){
		String sql = "insert into order_weixinpay_callback_record(orderNo, returnCode, return_msg, appId, partnerNo, deviceInfo, nonceStr, sign, resultCode, errCode, errCodeDes, openId, isSubscribe, tradeType, bankType, totalFee, feeType, cashFee, cashFeeType, couponFee, couponCount, tradeNo, attach, timeEnd, createTime,bizSystemCode) values(:orderNo, :returnCode, :returnMsg, :appId, :partnerNo, :deviceInfo, :nonceStr, :sign, :resultCode, :errCode, :errCodeDes, :openId, :isSubscribe, :tradeType, :bankType, :totalFee, :feeType, :cashFee, :cashFeeType, :couponFee, :couponCount, :tradeNo, :attach, :timeEnd, :createTime, :bizSystemCode)";
		BaseDAOUtil.updateObject(sql, this);
	}
	
	public void update(){
		String sql = "update order_weixinpay_callback_record set orderNo = :orderNo, returnCode = :returnCode, return_msg = :returnMsg, appId = :appId, partnerNo = :partnerNo, deviceInfo = :deviceInfo, nonceStr = :nonceStr, sign = :sign, resultCode = :resultCode, errCode = :errCode, errCodeDes = :errCodeDes, openId = :openId, isSubscribe = :isSubscribe, tradeType = :tradeType, bankType = :bankType, totalFee = :totalFee, feeType = :feeType, cashFee = :cashFee, cashFeeType = :cashFeeType, couponFee = :couponFee, couponCount = :couponCount, tradeNo = :tradeNo, attach = :attach, timeEnd = :timeEnd, createTime = :createTime , bizSystemCode=:bizSystemCode where orderNo = :orderNo";
		BaseDAOUtil.updateObject(sql, this);
	}
	
	public static WeiXinPayCallBackRecord getBy(String orderNo){
		String sql = "select orderNo, returnCode, return_msg as returnMsg, appId, partnerNo, deviceInfo, nonceStr, sign, resultCode, errCode, errCodeDes, openId, isSubscribe, tradeType, bankType, totalFee, feeType, cashFee, cashFeeType, couponFee, couponCount, tradeNo, attach, timeEnd, createTime,bizSystemCode from order_weixinpay_callback_record where orderNo = :orderNo";
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("orderNo", orderNo);
		return BaseDAOUtil.queryForObject(sql, paramMap, WeiXinPayCallBackRecord.class);
	}
	
	/**
	 * 根据多个订单号查询充电预约订单支付回调记录
	 * @param orderIds 订单号(多个)
	 * @return 充电预约订单支付回调记录
	 */
	public static List<WeiXinPayCallBackRecord> getByIds(List<String> orderNos){
		String sql = "select orderNo, returnCode, return_msg as returnMsg, appId, partnerNo, deviceInfo, nonceStr, sign, resultCode, errCode, errCodeDes, openId, isSubscribe, tradeType, bankType, totalFee, feeType, cashFee, cashFeeType, couponFee, couponCount, tradeNo, attach, timeEnd, createTime,bizSystemCode from order_weixinpay_callback_record where orderNo in (:orderNos)";
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("orderNos", orderNos);
		return BaseDAOUtil.queryForList(sql, paramMap, WeiXinPayCallBackRecord.class);
	}
}
